//
//  SDDetailViewController.m
//  YYPHSpeedJump
//
//  Created by speedjump on 15/12/22.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "SDDetailViewController.h"
#import "SDCommentTableViewCell.h"
#import "CommentView.h"
#import "BigImageViewController.h"
#import "THCPhotoModel.h"
#import "THCPhotoBrowser.h"
@interface SDDetailViewController ()<THCPhotoBrowserDelegate>
@property (nonatomic,strong)NSMutableArray* commentArr;
@property (nonatomic, strong) NSMutableArray * imageDataSource;
@end

@implementation SDDetailViewController
{
    UIView *topView;
    UIView * baseView;
    CommentView * commentView;
    UITableView *detailTableView;
    NSInteger page;
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden =NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    page = 1;
    // Do any additional setup after loading the view.
  self.navigationItem.title = @"晒单详情";
    [self createView];
    [self requestData];
    self.view.backgroundColor =kColors(239, 239, 244, 1);
    
}
- (void)setModel:(SDModel *)model
{
    _model = model;
}

- (NSMutableArray *)commentArr
{
    if(!_commentArr)
    {
        _commentArr = [NSMutableArray array];
    }
    return _commentArr;
}

 - (void)requestData
{
//    self.model.shaidan_id
    //@"http://192.168.1.199:8080/speedJump/app.do?cmd=shaidan_detail&shaidan_id=1&page=1"
    NSString *urlString = [NSString stringWithFormat:@"%@/app.do?cmd=shaidan_detail&shaidan_id=%@&page=%ld",kBaseUrl,self.model.shaidan_id, page];
    
    [NetworkHandle getUpDataWithUrl:urlString modelClass:NSClassFromString(@"SDCommentModel") firstKey:@"data" secondKey:@"list" success:^(NSArray *array) {
        if (page == 1) {
            [self.commentArr removeAllObjects];
        }
    [self.commentArr addObjectsFromArray:array];
        if (self.commentArr.count >= 10 && detailTableView.footer == nil) {
            detailTableView.footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
        }
        [detailTableView.header endRefreshing];
    [detailTableView reloadData];
}];
    
}


- (void)createView
{
    //文字内容的高度
    CGRect frame = [self.model.comment boundingRectWithSize:CGSizeMake(297*kWidthScale, 100000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    //NSLog(@"%f",frame.size.height);
    UILabel *goodName = [[UILabel alloc]init];
    goodName.font = [UIFont systemFontOfSize:12];
    goodName.text = self.model.name;
    [goodName setNumberOfLines:0];
    CGSize consstraint = CGSizeMake(kScreenWidth-100, 20000.0f);
    goodName.lineBreakMode = NSLineBreakByTruncatingTail;
    CGSize size = [goodName sizeThatFits:consstraint];
    [goodName setFrame:CGRectMake(65*kWidthScale, 34, size.width, size.height)];
    [topView addSubview:goodName];

    
     self.arr= [self.model.img_url_list componentsSeparatedByString:@";"];
    self.arr = [self.arr sortedArrayUsingSelector:@selector(compare:)];
    
    self.imageDataSource = [[NSMutableArray alloc] init];
    for (NSUInteger i=0; i< self.arr.count; i++) {
        THCPhotoModel *photoModel=[[THCPhotoModel alloc] init];
        photoModel.tag = i;
        photoModel.thumbnailPhotoURL = [NSURL URLWithString:self.arr[i]];
        photoModel.originalphotoURL = [NSURL URLWithString:self.arr[i]];
        [self.imageDataSource addObject:photoModel];
    }
    UIButton  *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [commentBtn setTitle:@"评论" forState:UIControlStateNormal];
    commentBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    commentBtn.frame = CGRectMake(0, 0, 40, 15);
    [commentBtn addTarget:self action:@selector(commentAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:commentBtn];
    UIView *baseOneView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, frame.size.height+goodName.frame.size.height+57+95*kWidthScale+41)];
    baseOneView.backgroundColor = kColors(239, 239, 244, 1);
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 9, kScreenWidth,frame.size.height+goodName.frame.size.height+57+95*kWidthScale+41)];
    topView.backgroundColor = kColors(255, 255, 255, 1);
    CGFloat sheng  = [self.model.original_price integerValue]-[self.model.buy_price integerValue];
       
    UILabel *moneyLable= [[UILabel alloc]initWithFrame:CGRectMake(5*kWidthScale,100 , 50, 10)];
    moneyLable.textAlignment = NSTextAlignmentCenter;
    moneyLable.text=[NSString stringWithFormat:@"省￥%.f",sheng];
    moneyLable.font = [UIFont systemFontOfSize:10];
    [topView addSubview:moneyLable];

    UIImageView *userImage= [[UIImageView alloc]initWithFrame:CGRectMake(13*kWidthScale, 14, 40, 40)];
    [userImage sd_setImageWithURL:[NSURL URLWithString:self.model.head_img_url] placeholderImage:nil];
    UIImageView *medalImage = [[UIImageView alloc]initWithFrame:CGRectMake(13*kWidthScale, 58, 40, 40)];
       //medalImage.image =[UIImage imageNamed:@"xz01"];
    CGFloat ratio=sheng/[self.model.original_price integerValue];
   
    if (ratio<0.1) {
        medalImage.image= [UIImage imageNamed:@"xz06"];
        [topView addSubview:medalImage];
    }
    if (0.1<=ratio && ratio <0.3) {
        medalImage.image= [UIImage imageNamed:@"xz01"];
        [topView addSubview:medalImage];
    }
    if (0.3<=ratio && ratio<0.5) {
        medalImage.image = [UIImage imageNamed:@"xz02"];
        [topView addSubview:medalImage];
    }
    if (0.5<=ratio && ratio<0.75) {
        medalImage.image = [UIImage imageNamed:@"xz03"];
        [topView addSubview:medalImage];
    }
    if (0.75<=ratio && ratio<1) {
        medalImage.image = [UIImage imageNamed:@"xz04"];
        [topView addSubview:medalImage];
    }
    if (ratio==1) {
       medalImage.image = [UIImage imageNamed:@"xz05"];
        [topView addSubview:medalImage];
    }
    

    
    
    UILabel *userLable = [[UILabel alloc]initWithFrame:CGRectMake(65*kWidthScale, 13, 112, 14)];
    userLable.text = self.model.nickname;
    userLable.font = [UIFont systemFontOfSize:14];
    
    
    UILabel *payPrice = [[UILabel alloc]initWithFrame:CGRectMake(65*kWidthScale, 36+goodName.frame.size.height, kScreenWidth-100, 10)];
    payPrice.text = [NSString stringWithFormat:@"购入价格:%@",self.model.buy_price];
    payPrice.font = [UIFont systemFontOfSize:10];
    payPrice.textColor = kColors(210, 2, 2, 1);
    [topView addSubview:payPrice];
    UILabel *timelable = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-120, 17*kHeightScale, 110, 10)];
    timelable.text = self.model.create_time;
    timelable.font = [UIFont systemFontOfSize:10];
    UILabel *contentlable = [[UILabel alloc]initWithFrame:CGRectMake(65*kWidthScale, goodName.frame.size.height+50, 240*kWidthScale, frame.size.height)];
    contentlable.font = [UIFont systemFontOfSize:12];
    contentlable.text=self.model.comment;
    //自动换行
    
    contentlable.numberOfLines = 0;
   
    if (self.arr.count ==1) {
        UIImageView *image1 =[[UIImageView alloc]initWithFrame:CGRectMake(65*kWidthScale, frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
        [topView addSubview:image1];
        image1.contentMode = UIViewContentModeScaleAspectFit;
        [image1 sd_setImageWithURL:[NSURL URLWithString:self.arr[0]] placeholderImage:nil];
      UITapGestureRecognizer *image1Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image1Action:)];
        image1.userInteractionEnabled = YES;
        image1.tag = 100;
        [image1 addGestureRecognizer:image1Recognizer];
    }
    if (self.arr.count ==2) {
        UIImageView *image1 =[[UIImageView alloc]initWithFrame:CGRectMake(66*kWidthScale, frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
        UITapGestureRecognizer *image1Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image1Action:)];
        [image1 addGestureRecognizer:image1Recognizer];
       
        UIImageView *image2 =[[UIImageView alloc]initWithFrame:CGRectMake(166*kWidthScale, frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
       image1.contentMode = UIViewContentModeScaleAspectFit;
        image2.contentMode = UIViewContentModeScaleAspectFit;
        [image1 sd_setImageWithURL:[NSURL URLWithString:self.arr[0]] placeholderImage:nil];
        [image2 sd_setImageWithURL:[NSURL URLWithString:self.arr[1]] placeholderImage:nil];
        UITapGestureRecognizer *image2Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image2Action:)];
        [image2 addGestureRecognizer:image2Recognizer];
         image1.userInteractionEnabled = YES;
        image2.userInteractionEnabled = YES;
        image1.tag = 100;
        image2.tag = 101;
        [topView addSubview:image1];
        [topView addSubview:image2];

    }
    if (self.arr.count ==3) {
        UIImageView *image1 =[[UIImageView alloc]initWithFrame:CGRectMake(66*kWidthScale, frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
        image1.contentMode = UIViewContentModeScaleAspectFit;
        [topView addSubview:image1];
        [image1 sd_setImageWithURL:[NSURL URLWithString:self.arr[0]] placeholderImage:nil];
        UIImageView *image2 =[[UIImageView alloc]initWithFrame:CGRectMake(166*kWidthScale, frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
        image2.contentMode = UIViewContentModeScaleAspectFit;
        [topView addSubview:image2];
        [image2 sd_setImageWithURL:[NSURL URLWithString:self.arr[1]] placeholderImage:nil];
        UIImageView *image3 =[[UIImageView alloc]initWithFrame:CGRectMake(267*kWidthScale,frame.size.height+goodName.frame.size.height+57, 95*kWidthScale, 95*kWidthScale)];
        image3.contentMode = UIViewContentModeScaleAspectFit;
        [topView addSubview:image3];
        [image3 sd_setImageWithURL:[NSURL URLWithString:self.arr[2]] placeholderImage:nil];
        UITapGestureRecognizer *image1Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image1Action:)];
        [image1 addGestureRecognizer:image1Recognizer];
        UITapGestureRecognizer *image2Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image2Action:)];
        [image2 addGestureRecognizer:image2Recognizer];
        UITapGestureRecognizer *image3Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(image3Action:)];
        [image3 addGestureRecognizer:image3Recognizer];
         image1.userInteractionEnabled = YES;
         image2.userInteractionEnabled = YES;
         image3.userInteractionEnabled = YES;
        image1.tag = 100;
        image2.tag = 101;
        image3.tag = 102;
    }
    self.xianmuButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.xianmuButton.frame = CGRectMake(kScreenWidth-249,frame.size.height+goodName.frame.size.height+57+95*kWidthScale+6, 44, 25);
    [self.xianmuButton setBackgroundImage:[UIImage imageNamed:@"xm"] forState:UIControlStateNormal];
    [self.xianmuButton addTarget:self action:@selector(xianmuButtonAct:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:self.xianmuButton];
    self.jiduButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.jiduButton.frame = CGRectMake(kScreenWidth-164, frame.size.height+goodName.frame.size.height+57+95*kWidthScale+6, 44, 25);
    [self.jiduButton setBackgroundImage:[UIImage imageNamed:@"jd"] forState:UIControlStateNormal];
    [self.jiduButton addTarget:self action:@selector(jiduButtonAct:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:self.jiduButton];
    self.henButton= [UIButton buttonWithType:UIButtonTypeCustom];
    self.henButton.frame = CGRectMake(kScreenWidth-80, frame.size.height+goodName.frame.size.height+57+95*kWidthScale+6, 32, 25);
    [self.henButton setBackgroundImage:[UIImage imageNamed:@"h"] forState:UIControlStateNormal];
    [self.henButton addTarget:self action:@selector(henButtonAct:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:self.henButton];
    self.xianmu = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-204, frame.size.height+goodName.frame.size.height+57+95*kWidthScale+11, 52, 13)];
    self.xianmu.textColor = kColors(218, 166, 46, 1);
    self.xianmu.text= [NSString stringWithFormat:@"(%@)",self.model.xianmu_num];
    self.xianmu.font = [UIFont systemFontOfSize:12];
    [topView addSubview:self.xianmu];
    self.jidu = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-119, frame.size.height+goodName.frame.size.height+57+95*kWidthScale+11, 52, 13)];
    self.jidu.textColor = kColors(218, 166, 46, 1);
    self.jidu.text= [NSString stringWithFormat:@"(%@)",self.model.jidu_num];
    self.jidu.font = [UIFont systemFontOfSize:12];
    [topView addSubview:self.jidu];
    self.hen = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-46
                                                        , frame.size.height+goodName.frame.size.height+57+95*kWidthScale+11, 52, 13)];
    self.hen.textColor = kColors(218, 166, 46, 1);
    self.hen.text= [NSString stringWithFormat:@"(%@)",self.model.hen_num];
    self.hen.font = [UIFont systemFontOfSize:12];
    [topView addSubview:self.hen];
    
    [topView addSubview:userImage];
    [topView addSubview:userLable];
    [topView addSubview:timelable];
    [topView addSubview:contentlable];
    
    [baseOneView addSubview:topView];
    detailTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-64)];
    detailTableView.delegate = self;
    detailTableView.dataSource =self;
    detailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    detailTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
    [self.view addSubview:detailTableView];
    detailTableView.tableHeaderView =baseOneView;

}
- (void)xianmuButtonAct:(UIButton*)btn{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"logined"]) {
        [Tools showAlert:@"您还未登录,请到个人登录!"];
        return;
    }
   
    NSString *url = [NSString stringWithFormat:@"%@%@", kBaseUrl, kSDPraiseUrl];
    //NSLog(@"%@",cell.model.shaidan_id);
    NSDictionary *dic = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"shaidan_id":self.model.shaidan_id,@"pro_type":@"1"};
    [NetworkHandle getInfoWithUrl:url dictionary:dic success:^(NSDictionary *dictionary) {
        //NSLog(@"%@", dictionary);
        if([dictionary[@"code"] isEqualToString:@"200"]) {
            
           self.xianmu.text = [NSString stringWithFormat:@"(%ld)", [self.model.xianmu_num integerValue] + 1];
            self.model.xianmu_num = self.xianmu.text;
            
            
        }
        else
        {
            [Tools showAlert:dictionary[@"message"]];
            
        }
    }];

}
- (void)jiduButtonAct:(UIButton*)btn{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"logined"]) {
        [Tools showAlert:@"您还未登录,请到个人登录!"];
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kBaseUrl, kSDPraiseUrl];
    //NSLog(@"%@",cell.model.shaidan_id);
    NSDictionary *dic = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"shaidan_id":self.model.shaidan_id,@"pro_type":@"2"};
    [NetworkHandle getInfoWithUrl:url dictionary:dic success:^(NSDictionary *dictionary) {
        //NSLog(@"%@", dictionary);
        if([dictionary[@"code"] isEqualToString:@"200"]) {
            
            self.jidu.text = [NSString stringWithFormat:@"(%ld)", [self.model.jidu_num integerValue] + 1];
            self.model.jidu_num = self.jidu.text;
            
            
        }
        else
        {
            [Tools showAlert:dictionary[@"message"]];
            
        }
    }];

}
- (void)henButtonAct:(UIButton*)btn{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"logined"]) {
        [Tools showAlert:@"您还未登录,请到个人登录!"];
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kBaseUrl, kSDPraiseUrl];
    //NSLog(@"%@",cell.model.shaidan_id);
    NSDictionary *dic = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"shaidan_id":self.model.shaidan_id,@"pro_type":@"3"};
    [NetworkHandle getInfoWithUrl:url dictionary:dic success:^(NSDictionary *dictionary) {
        //NSLog(@"%@", dictionary);
        if([dictionary[@"code"] isEqualToString:@"200"]) {
            
            self.hen.text = [NSString stringWithFormat:@"(%ld)", [self.model.hen_num integerValue] + 1];
            self.model.hen_num = self.hen.text;
            
            
        }
        else
        {
            [Tools showAlert:dictionary[@"message"]];
            
        }
    }];

}
- (void)headerRereshing
{
    page = 1;
    [self requestData];
}

- (void)footerRefresh
{
    page++;
    [self requestData];
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    //if (section == 0) {
    
    
    UILabel *headerLable = [[UILabel alloc]initWithFrame:CGRectMake(12, 16, 200, 15)];
    headerLable.text = @"评论列表";
    headerLable.font = [UIFont systemFontOfSize:14];
    
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 44)];
    [sectionView addSubview:headerLable];
    return sectionView;
    //    }
    //    return nil;
    //
}

#pragma mark -------------评论--------------
- (void)commentAction:(UIButton *)btn
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"logined"]) {
        [Tools showAlert:@"您还未登录,请到个人登录!"];
        return;
    }
    baseView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    baseView.backgroundColor = [UIColor grayColor];
    baseView.alpha = 0.5;
    [self.view.window addSubview:baseView];
    commentView = [[CommentView alloc]initWithFrame:CGRectMake(13*kWidthScale, 167*kHeightScale, 349*kWidthScale, 163*kHeightScale)];
    // commentView.layer.cornerRadius = 5;
    // commentView.backgroundColor = kColors(255, 255, 255, 1);
    [self.view.window addSubview:commentView];
    
    [commentView.returnBtn addTarget:self action:@selector(returnAct:) forControlEvents:UIControlEventTouchUpInside];
    [commentView.commentBtn addTarget:self action:@selector(commentAct:) forControlEvents:UIControlEventTouchUpInside];
    
}
//返回
- (void)returnAct:(UIButton*)btn
{
    [baseView removeFromSuperview];
    [commentView removeFromSuperview];
    
}
//确认
- (void)commentAct:(UIButton*)btn
{
    NSString *text = [commentView.commentText.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    [commentView.commentText resignFirstResponder];
    if (text.length < 6) {
        [Tools showAlert:@"输入不能小于6个字符!"];
        return;
    }
    NSString *urlStr = [NSString stringWithFormat:@"%@/user.do?cmd=make_comment_in_shaidan",kBaseUrl];
    NSDictionary *dic = @{@"comment_content":commentView.commentText.text,@"shaidan_id":self.model.shaidan_id,@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"]};
    
    [NetworkHandle getUpDataWithUrl:urlStr class:NSClassFromString(@"SDCommentModel") dictionary:dic firstKey:@"data" secondKey:@"list" success:^(NSArray *array) {
        
        self.commentArr = [NSMutableArray arrayWithArray:array];
        
        // NSLog(@"%@",self.commentArr);
        [detailTableView reloadData];
    }];
    
    
    
    [baseView removeFromSuperview];
    [commentView removeFromSuperview];
    
}
#pragma mark ----------------tableView---------------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.commentArr.count > 0) {
        return self.commentArr.count;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SDCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"SDCommentTableViewCell" owner:nil options:nil]lastObject];
        //cell.userName.text = _array[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.model = self.commentArr[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 69;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 44;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat sectionHeaderHeight = 44;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    }
    else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}
#pragma mark--------点击看大图-----------
- (void)image1Action:(UIButton *)btn
{
   // BigImageViewController *bigimage = [[BigImageViewController alloc]init];
   // [self.navigationController pushViewController:bigimage animated:YES];
   //bigimage.view.backgroundColor = [UIColor blackColor];
  //  bigimage.imgUrl = self.arr[0];
//   [bigimage.bigImage sd_setImageWithURL:[NSURL URLWithString:self.arr[0]] placeholderImage:nil];
    THCPhotoBrowser * photoBrowser = [[THCPhotoBrowser alloc] init];
    photoBrowser.delegate = self;
    [photoBrowser presentFromViewController:self index:0];
}
- (void)image2Action:(UIButton *)btn
{
   // BigImageViewController *bigimage = [[BigImageViewController alloc]init];
   // [self.navigationController pushViewController:bigimage animated:YES];
//     bigimage.view.backgroundColor = [UIColor blackColor];
//    [bigimage.bigImage sd_setImageWithURL:[NSURL URLWithString:self.arr[1]] placeholderImage:nil];
   //  bigimage.imgUrl = self.arr[1];
    THCPhotoBrowser * photoBrowser = [[THCPhotoBrowser alloc] init];
    photoBrowser.delegate = self;
    [photoBrowser presentFromViewController:self index:1];

}
- (void)image3Action:(UIButton *)btn
{
  //  BigImageViewController *bigimage = [[BigImageViewController alloc]init];
  //  [self.navigationController pushViewController:bigimage animated:YES];
//    bigimage.view.backgroundColor = [UIColor blackColor];
//    [bigimage.bigImage sd_setImageWithURL:[NSURL URLWithString:self.arr[2]] placeholderImage:nil];
 //    bigimage.imgUrl = self.arr[2];
    
    THCPhotoBrowser * photoBrowser = [[THCPhotoBrowser alloc] init];
    photoBrowser.delegate = self;
    [photoBrowser presentFromViewController:self index:2];
}
#pragma mark - THCPhotoBrowserDelegate
- (NSInteger)numberOfPhotosInPhotoBrowser:(THCPhotoBrowser *)photoBrowser
{
    return self.arr.count;
}

-(THCPhotoModel*)photoBrowser:(THCPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
{
    THCPhotoModel * photoModel = self.imageDataSource[index];
    //ImageViewCell * cell = (ImageViewCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
    UIImageView *imageView = [topView viewWithTag:100+index];
    photoModel.sourceImageView = imageView;
    
    return photoModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc
{

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
